package com.bappi.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.post799.soundapp.R;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.Paint.Align;

public class ImageUtils {

	public static final Bitmap getResizeImage(Bitmap bitmap, int width,
			int height) {
		Bitmap ret = Bitmap
				.createBitmap(width, height, Bitmap.Config.ARGB_8888);
		Canvas comboImage = new Canvas(ret);
		Rect r1 = new Rect(0, 0, width, height);
		Rect r2 = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
		comboImage.drawBitmap(bitmap, r2, r1, null);
		comboImage.save();
		return ret;
	}

	private static final float IMAGE_BUTTON_FACTOR = 0.5F;

	public static final Bitmap getImage(Resources res, float dpiFactor,int id) {
		Bitmap temp1 = BitmapFactory.decodeResource(res, id);
		float factor = dpiFactor*IMAGE_BUTTON_FACTOR;
		Bitmap ret = Bitmap.createBitmap((int) (factor*temp1.getWidth()),
				(int) (factor*temp1.getHeight()), Bitmap.Config.ARGB_8888);
		Canvas comboImage = new Canvas(ret);
		Rect r1 = new Rect(0, 0, temp1.getWidth(), temp1.getHeight());
		Rect r2 = new Rect(0, 0, ret.getWidth(),ret.getHeight());
		comboImage.drawBitmap(temp1, r1, r2, null);
		comboImage.save();
		return ret;
	}

	// public static final Bitmap getCalendarImage(Resources res,float
	// dpiFactor) {
	//
	// Bitmap temp1 = BitmapFactory.decodeResource(res, R.drawable.calendar);
	// Bitmap ret = Bitmap.createBitmap(temp1.getWidth(), temp1.getHeight(),
	// Bitmap.Config.ARGB_8888);
	// Canvas comboImage = new Canvas(ret);
	// Rect r1 = new Rect(0, 0, temp1.getWidth(), temp1.getHeight());
	// comboImage.drawBitmap(temp1, r1, r1, null);
	// Paint paint = new Paint();
	// paint.setAntiAlias(true);
	// paint.setColor(0xFFFFFFFF);
	// paint.setTextSize(30*dpiFactor);
	// paint.setTextAlign(Align.CENTER);
	// paint.setTypeface(Typeface.DEFAULT_BOLD);
	// Date date = new Date();
	// comboImage.drawText(MONTH.format(date),temp1.getWidth()/2,64*dpiFactor,paint);
	// paint.setTextSize(80*dpiFactor);
	// paint.setColor(0xFF000000);
	// comboImage.drawText(DAY.format(date),temp1.getWidth()/2,164*dpiFactor,paint);
	//
	// // comboImage.drawText(printValue, temp2.getWidth() / 2,
	// // 3 * temp2.getWidth() / 4, paint);
	// comboImage.save();
	// return ret;
	// }
}
